// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import FastClick from 'fastclick'
import axios from 'axios'
import { LoadingPlugin } from 'vux'

Vue.prototype.$baseUrl = ''
Vue.prototype.$axios = axios.create({
  headers: { 'AUTH-TOKEN': localStorage.getItem('AUTH-TOKEN') },
  timeout: 5000
})

import './assets/css/reset.css' // 样式初始化文件
import './assets/css/border.css' // 边框初始化文件

FastClick.attach(document.body) // 全局处理点击延迟300毫秒bug

Vue.use(LoadingPlugin)
Vue.config.productionTip = false

// 格式化时间的过滤器
Vue.filter('dateFormat', originVal => {
  var myDate = new Date().getTime()
  var gapDate = myDate - originVal
  const dd = new Date(myDate)
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1).toString().padStart(2, '0')
  const d = dt
    .getDate()
    .toString()
    .padStart(2, '0')
  const ds = dd
    .getDate()
    .toString()
    .padStart(2, '0')

  const hh = dt
    .getHours()
    .toString()
    .padStart(2, '0')
  const mm = dt
    .getMinutes()
    .toString()
    .padStart(2, '0')
  const ss = dt
    .getSeconds()
    .toString()
    .padStart(2, '0')

  if (gapDate < 86400000) {
    if (ds != d) {
      return `昨天 ${hh}:${mm}:${ss}`
    } else {
      return `今天 ${hh}:${mm}:${ss}`
    }
  } else {
    return `${y}/${m}/${d}`
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
